import Vector2 from '@/common/plugins/js/Vector2'

export default class Mouse {
  constructor() {
    const self = this
    const evts = ['mouseenter', 'mousemove', 'mouseout', 'mousedown', 'mouseup', 'dblclick']
    this.hover = false
    this.mousedown = false
    this.dblclick = false
    this.position = new Vector2()
    for (const evt of evts) {
      window.addEventListener(evt, self.handler.bind(self))
    }
  }

  handler(e) {
    switch (e.type) {
      case 'mousedown':
        this.mousedown = true
        break
      case 'mouseup':
        this.mousedown = false
        break
      case 'mouseenter':
        this.hover = true
        break
      case 'mousemove':
        this.hover = true
        break
      case 'mouseout':
        this.hover = false
        break
      case 'dblclick':
        this.dblclick = true
        break
      default:
        break
    }

    if (this.hover) {
      this.position.x = e.clientX
      this.position.y = e.clientY
    }
  }
}
